package com.example.task1.ui.AllService.thehouse;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.TheHouseBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class TheHouseAdapter extends BaseAdapter<TheHouseBean.RowsDTO> {

    private List<TheHouseBean.RowsDTO> data = new ArrayList<>();
    private Context context;
    private ImageView image;
    private TextView tvTitle;
    private TextView tvAddress;
    private TextView tvPrice;
    private TextView tvHouseType;

    public TheHouseAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<TheHouseBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.thehouselist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<TheHouseBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, TheHouseBean.RowsDTO date) {
        MyApplication.glide(image, date.getPic());
        tvAddress.setText("地址：" + date.getAddress());
        tvHouseType.setText("房源类型：" + date.getHouseType());
        tvTitle.setText(date.getSourceName());
        tvPrice.setText("价格：" + date.getPrice());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, TheHouseDetailsActivity.class, date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        image = (ImageView) itemView.findViewById(R.id.image);
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvAddress = (TextView) itemView.findViewById(R.id.tv_address);
        tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
        tvHouseType = (TextView) itemView.findViewById(R.id.tv_houseType);
    }
}
